<?php
	namespace Qzn\View;
	class MemberListView {
		
		private $m_removeButton = "Remove";
		private $m_promoteButton = "Promote";
		
		/**
		 * @return string $html
		 */
		public function MemberListBox (\Qzn\Model\MemberListHandler $mlh, \Qzn\View\LoginView $lw) {
			$html = "<div>
						<form method='post'>
							<fieldset>
								<ul>";
			
			$memberList = $mlh->GetMemberList();
			
			foreach ($memberList as $value) {
				if ($value[0] != $lw->GetUserName()) {
					if ($value[2] >= 3 || $lw->GetUserCat() <= 2) {
						$html .= "<li><a href='?profile=$value[1]'> $value[0]</a></li>";
					} else if ($value[2] >= 2) {
						$html .= "<li><input type='submit' name='$value[1]' value='$this->m_removeButton' /><a href='?profile=$value[1]'> $value[0]</a></li>";
					} else {
						$html .= "<li><input type='submit' name='$value[1]' value='$this->m_promoteButton' /><input type='submit' name='$value[1]' value='$this->m_removeButton' /><a href='?profile=$value[1]'> $value[0]</a></li>";
					}
				}
			}
			
			$html .= "			</ul>
							</fieldset>
						</form>
					</div>";			
			
			return $html;
		}
		
		/**
		 * @return boolean removeButton
		 */
		public function TriedToRemoveMember() {
			if (count(array_keys($_POST, $this->m_removeButton)) == 1) {
				return true;
			}
			
			return false;
		}
		
		/**
		 * @return boolean promoteButton
		 */
		public function TriedToPromoteMember() {
			if (count(array_keys($_POST, $this->m_promoteButton)) == 1) {
				return true;
			}
			
			return false;
		}
		
		/**
		 * @return string $ret
		 */
		public function GetRemoveUser() {
			if (count(array_keys($_POST, $this->m_removeButton)) == 1) {
				$ret = array_keys($_POST, $this->m_removeButton);
				$ret = end($ret);
				return $ret;
			}
			return null;
		}
		
		/**
		 * @return string $ret
		 */
		public function GetPromoteUser() {
			if (count(array_keys($_POST, $this->m_promoteButton)) == 1) {
				$ret = array_keys($_POST, $this->m_promoteButton);
				$ret = end($ret);
				return $ret;
			}
			return null;
		}
	}
?>